package com.event.cacheclear.config;

import cn.hutool.core.collection.CollUtil;
import com.event.common.face.IClearNameSpace;
import com.event.common.model.AliasClearNameSpace;
import com.event.core.parse.CacheableParse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * @description BEAN配置
 * @author Bing
 * @date 2024/10/8 12:44
 **/
@Configuration
@ConditionalOnBean(CacheableParse.class)
public class BeanConfig {

    @Autowired(required = false)
    private List<IClearNameSpace> clearNameSpaces;
    
    @Bean
    public AliasClearNameSpace aliasClearNameSpacesMap(){
        Map<String, IClearNameSpace<Object>> aliasClearNameSpacesMap = new HashMap<>();
        if(CollUtil.isEmpty(clearNameSpaces)){
            return new AliasClearNameSpace(aliasClearNameSpacesMap);
        }
        for(IClearNameSpace item : clearNameSpaces){
            aliasClearNameSpacesMap.put(item.namespaceAlias(), item);
        }
        return new AliasClearNameSpace(aliasClearNameSpacesMap);
    }
 }
